package com.opennews.openplatform

import groovy.transform.CompileStatic
import org.springframework.http.HttpStatus

@CompileStatic
class JourneyController extends BaseController {
    static allowedMethods = [
        add: "POST",
        update: "POST",
        delete: "POST"
    ]

    JourneyService journeyService

    // region: Get actions.
    def index() {
        render("JourneyController")
    }

    def queryListByAccountGroup() {
        def pageSize = params.int("pageSize")
        def pageIndex = params.int("pageIndex")
        def accountGroupId = getClaims().accountGroupId
        def result = journeyService.queryListByAccountGroup(accountGroupId, pageSize, pageIndex)

        sendDataResponse(result)
    }
    //endregion

    // region: Post actions.
    def add() {
        def requestBodyData = getRequestBodyData()
        def accountGroupId = getClaims().accountGroupId
        journeyService.add(accountGroupId, requestBodyData)

        sendStatusResponse(HttpStatus.NO_CONTENT)
    }

    def update() {
        def requestBodyData = getRequestBodyData()
        def accountGroupId = getClaims().accountGroupId
        journeyService.update(accountGroupId, requestBodyData)

        sendStatusResponse(HttpStatus.NO_CONTENT)
    }

    def delete() {
        def requestBodyData = getRequestBodyData()
        def id = requestBodyData.id.toString()
        def accountGroupId = getClaims().accountGroupId
        def result = journeyService.delete(accountGroupId, id)

        sendDataResponse(result)
    }
    // endregion
}